using Admin2505.Domain.Entityes.App;
using Admin2505.Iinfrastructure.Secunity;
using Microsoft.EntityFrameworkCore;

namespace Admin2505.Iinfrastructure.Data;

public class Admin2505DbContext : DbContext
{
    public Admin2505DbContext(DbContextOptions options) : base(options)
    {}
    public DbSet<AppUser> AppUser { get;set;}

    public DbSet<AppRole> AppRole  {get;set;}

    public DbSet<Apppermission> Apppermmission { get; set; }

    public DbSet<AppUserRole> AppUserRole { get; set; }

    public DbSet<AppRolePermission> AppRolePermission { get; set; }


    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);
        
        var adminUserId = Guid.Parse("00000000-0000-0000-0000-000000000001");
        var adminRoleId = Guid.Parse("00000000-0000-0000-0000-000000000002");
        var perUserManageid= Guid.Parse("00000000-0000-0000-0000-000000000003");
        var perRoleManageid = Guid.Parse("00000000-0000-0000-0000-000000000004");

        var dafeultTime = new DateTime(2023, 10, 1, 0, 0, 0,DateTimeKind.Utc);
    


        //用户
        modelBuilder.Entity<AppUser>().HasData(
            new{
                Id = adminUserId,
                Username = "admin",
                Password="113",
                Salt="333",
                // Description = "系统管理员",
                CreatedAt = dafeultTime,
                UpdatedAt = dafeultTime,
                IsActived = true,
                IsDelete = false,
                CreatedBy = Guid.Empty,
                UpdatedBy = Guid.Empty,
                DisplayOrder = 0,
                Remarks = ""
            }
        );
        //角色
        modelBuilder.Entity<AppRole>().HasData(
            new{
                Id = adminRoleId,
                RoleName = "admin",
                // Description = "系统管理员",
                CreatedAt = dafeultTime,
                UpdatedAt = dafeultTime,
                IsActived = true,
                IsDelete = false,
                CreatedBy = Guid.Empty,
                UpdatedBy = Guid.Empty,
                DisplayOrder = 0,
                Remarks = ""
            }
        );
        //权限
        modelBuilder.Entity<Apppermission>().HasData(
           new{
                Id = perUserManageid,
                Name = "admin",
                Description = "系统管理员",
                CreatedAt = dafeultTime,
                UpdatedAt = dafeultTime,
                IsActived = true,
                IsDelete = false,
                CreatedBy = Guid.Empty,
                UpdatedBy = Guid.Empty,
                DisplayOrder = 0,
                Remarks = ""
            },
            new{
                Id = perRoleManageid,
                Name = "超级管理员",
                Description = "系统超级管理员",
                CreatedAt = dafeultTime,
                UpdatedAt = dafeultTime,
                IsActived = true,
                IsDelete = false,
                CreatedBy = Guid.Empty,
                UpdatedBy = Guid.Empty,
                DisplayOrder = 0,
                Remarks = ""
            }
        );
        //用户角色
        modelBuilder.Entity<AppUserRole>().HasData(
         
            new{
                Id = Guid.NewGuid(),
                UserId = adminUserId,
                RoleId = adminRoleId,
                // Name = "admin",
                // Description = "系统管理员",
                CreatedAt = dafeultTime,
                UpdatedAt = dafeultTime,
                IsActived = true,
                IsDelete = false,
                CreatedBy = Guid.Empty,
                UpdatedBy = Guid.Empty,
                DisplayOrder = 0,
                Remarks = ""
            }
        );
        //角色权限
        modelBuilder.Entity<AppRolePermission>().HasData(
            new{
                Id = Guid.NewGuid(),
                RoleId = adminRoleId,
                PermissionId = perUserManageid,
                // Name = "admin",
                // Description = "系统管理员",
                CreatedAt = dafeultTime,
                UpdatedAt = dafeultTime,
                IsActived = true,
                IsDelete = false,
                CreatedBy = Guid.Empty,
                UpdatedBy = Guid.Empty,
                DisplayOrder = 0,
                Remarks = ""
            },
            new{
                Id =Guid.NewGuid(),
                RoleId = adminRoleId,
                PermissionId = perRoleManageid,
                // Name = "超级管理员",
                // Description = "系统超级管理员",
                CreatedAt = dafeultTime,
                UpdatedAt = dafeultTime,
                IsActived = true,
                IsDelete = false,
                CreatedBy = Guid.Empty,
                UpdatedBy = Guid.Empty,
                DisplayOrder = 0,
                Remarks = ""
            }
            );
    }


} 